package cn.itcast.bos.domain.auth;

// Generated 2016-5-4 16:20:01 by Hibernate Tools 3.2.2.GA

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.GenericGenerator;

import cn.itcast.bos.domain.user.User;

/**
 * Role generated by hbm2java
 */
@Entity
@Table(name = "AUTH_ROLE", schema = "ITCAST27", uniqueConstraints = @UniqueConstraint(columnNames = "NAME"))
public class Role implements java.io.Serializable {

	private String id;
	private String name;
	private String code;
	private String description;
	private Set<User> users = new HashSet<User>(0);
	private Set<Function> functions = new HashSet<Function>(0);// 集合

	public Role() {
	}

	public Role(String name, String code, String description, Set<User> users, Set<Function> functions) {
		this.name = name;
		this.code = code;
		this.description = description;
		this.users = users;
		this.functions = functions;
	}

	@GenericGenerator(name = "generator", strategy = "uuid")
	@Id
	@GeneratedValue(generator = "generator")
	@Column(name = "ID", unique = true, nullable = false, length = 32)
	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name = "NAME", unique = true)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "CODE")
	public String getCode() {
		return this.code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	@Column(name = "DESCRIPTION")
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "USER_ROLE", schema = "ITCAST27", joinColumns = { @JoinColumn(name = "ROLE_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "USER_ID", nullable = false, updatable = false) })
	public Set<User> getUsers() {
		return this.users;
	}

	public void setUsers(Set<User> users) {
		this.users = users;
	}

	// cascade = CascadeType.ALL, 当添加role 试图 更新 function
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "ROLE_FUNCTION", schema = "ITCAST27", joinColumns = { @JoinColumn(name = "ROLE_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "FUNCTION_ID", nullable = false, updatable = false) })
	public Set<Function> getFunctions() {
		return this.functions;
	}

	public void setFunctions(Set<Function> functions) {
		this.functions = functions;
	}

}
